$(function () {
    var token = localStorage.getItem("jwt");
    var seminarId = localStorage.getItem("seminarId");
    console.log(seminarId);

    var courseJson = localStorage.getItem("courseJson");
    courseJson = JSON.parse(courseJson);
    $(".courseName").text(courseJson.name);
    $(".courseIntroduction").text(courseJson.description);

    //获取所有小组信息
    $.ajax({
        url:"/seminar/"+seminarId+"/group",
        // url: "http://rap.taobao.org/mockjsdata/29816/seminar/32/group",
        type: "GET",
        headers: {"Authorization": "Bearer " + token},
        success: function (data) {
            console.log(data);
            localStorage.setItem("groupTopicDetail", JSON.stringify(data));
            if (data.length != undefined) {
                for (var i = 0; i < data.length; i++) {
                    $(".tableContent").append("  <tr>\n" +
                        "                    <td>" + data[i].topicName + "</td>\n" +
                        "                    <td>" + data[i].groupName + "</td>\n" +
                        "                    <td>" + data[i].leader + "</td>\n" +
                        "                    <td>" + (data[i].presentationGrade == undefined ? "" : data[i].presentationGrade) + "</td>\n" +
                        "                    <td>" + data[i].reportStatus + "</td>\n" +
                        "                    <td>" + (data[i].reportGrade == undefined ? "" : data[i].reportGrade) + "</td>\n" +
                        "                    <td>" + (data[i].finalGrade == undefined ? "" : data[i].finalGrade) + "</td>\n" +
                        "                    <td>\n" +
                        "                         <img src=\"/img/view.png\" alt=\"预览\" name='report' id=\"" + i +"\">\n" +
                        "                        <a href=\"" + data[i].report + "\" download='report'><img src=\"/img/download.png\" alt=\"下载\" name='download'></a>\n" +
                        "                    </td>\n" +
                        "                </tr>")
                }
            }

        }
    })

    //跳转到pdf预览界面
    $(".body").on("click", "[name=report]", function () {
        var groupIndex = $(this).attr("id");
        // console.log(groupId);
        localStorage.setItem("groupIndex", groupIndex);
        window.location.href = "/teacher/scoreReport";
    });

    //返回上一页
    $(".returnButton").click(function () {
        window.history.back();
    })
})